using System;
using Microsoft.SPOT;

namespace Microsoft.Xna.Framework
{
    public struct Vector2
    {
        private static Vector2 zero = new Vector2(0);
        private static Vector2 one = new Vector2(1);
        private static Vector2 unitX = new Vector2(1, 0);
        private static Vector2 unitY = new Vector2(0, 1);

        public float X;
        public float Y;

        public static Vector2 Zero
        {
            get { return zero; }
        }

        public static Vector2 One
        {
            get { return one; }
        }

        public static Vector2 UnitX
        {
            get { return unitX; }
        }

        public static Vector2 UnitY
        {
            get { return unitY; }
        }

        public Vector2(float value)
        {
            this.X = value;
            this.Y = value;
        }

        public Vector2(float x, float y)
        {
            this.X = x;
            this.Y = y;
        }

        public override int GetHashCode()
        {
            return this.X.GetHashCode() + this.Y.GetHashCode();
        }

        public static Vector2 Add(Vector2 value1, Vector2 value2)
        {
            return new Vector2(value1.X + value2.X, value1.Y + value2.Y);
        }

        public static Vector2 operator +(Vector2 value1, Vector2 value2)
        {
            return new Vector2(value1.X + value2.X, value1.Y + value2.Y);
        }

        public static Vector2 Subtract(Vector2 value1, Vector2 value2)
        {
            return new Vector2(value1.X - value2.X, value1.Y - value2.Y);
        }

        public static Vector2 operator -(Vector2 value1, Vector2 value2)
        {
            return new Vector2(value1.X - value2.X, value1.Y - value2.Y);
        }

        public static Vector2 operator -(Vector2 value)
        {
            return new Vector2(-value.X, -value.Y);
        }

        public static Vector2 operator *(Vector2 value1, Vector2 value2)
        {
            return new Vector2(value1.X * value2.X, value1.Y * value2.Y);
        }

        public static Vector2 operator *(Vector2 value1, float value2)
        {
            return new Vector2(value1.X * value2, value1.Y * value2);
        }

        public static Vector2 operator /(Vector2 value1, float value2)
        {
            float divisor = 1 / value2;
            return new Vector2(value1.X * divisor, value1.Y * divisor);
        }

        public bool Equals(Vector2 value)
        {
            return value.X == this.X && value.Y == this.Y;
        }

        public override bool Equals(object obj)
        {
            if (obj is Vector2)
            {
                return Equals((Vector2)obj);
            }
            return false;
        }

        public static bool operator ==(Vector2 value1, Vector2 value2)
        {
            return (value1.X == value2.X) && (value1.Y == value2.Y);
        }

        public static bool operator !=(Vector2 value1, Vector2 value2)
        {
            return (value1.X != value2.X) || (value1.Y != value2.Y);
        }

        public override string ToString()
        {
            return string.Concat("{X:", X.ToString(), " Y:", Y.ToString(), "}");
        }

        public float LengthSquared()
        {
            return X * X + Y * Y;
        }
    }
}
